package com.itheima.health.service.impl;

import com.itheima.health.dao.MemberDao;
import com.itheima.health.dao.UserDao;
import com.itheima.health.pojo.Member;
import com.itheima.health.pojo.User;
import com.itheima.health.service.MemberService;
import com.itheima.health.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author zhangmeng
 * @description 用户服务实现类
 * @date 2019/9/6
 **/
@Slf4j
@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    /**
     * 创建/更新会员
     *
     * @param member
     * @return
     */
    @Override
    public Member createOrUpdate(Member member) {
       Member mem= memberDao.getByPhone(member.getPhoneNumber());
       if (mem != null){
           member.setId(mem.getId());
           memberDao.update(member);
       }else {
           member.setRegTime(new Date());
           memberDao.insert(member);
       }
        return memberDao.getById(member.getId());
    }
}
